package com.parsechina.hpush.broker.internal.subscriptions;

import java.util.Objects;

/**
 * Internal use only class.
 *
 * @author linfeng*/
public class Token {

    static final Token EMPTY = new Token("");
    static final Token MULTI = new Token("#");
    static final Token SINGLE = new Token("+");
    private final String name;

    Token(String s) {
        name = s;
    }

    public String name() {
        return name;
    }

    boolean match(Token t) {
        if (t == MULTI || t == SINGLE) {
            return false;
        }

        if (this == MULTI || this == SINGLE) {
            return true;
        }

        return equals(t);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Token token = (Token) o;
        return Objects.equals(name, token.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name);
    }

    @Override
    public String toString() {
        return name;
    }
}
